<?php 
header("content-Type: text/html; charset=utf-8");
ob_start();
session_start();
ini_set("magic_quotes_runtime", 0);
error_reporting(0);
date_default_timezone_set('Asia/Shanghai');
require_once('conn.inc.php');


function webfunc($colname, $tablename){
	$result = mysql_query("select $colname from $tablename");
	$row = mysql_fetch_array($result);
	return $row[$colname];
}

function webfunc_w($colname, $tablename, $w){
	$result = mysql_query("select $colname from $tablename where $w");
	$row = mysql_fetch_array($result);
	return $row[$colname];
}


function webfunc_c($tablename, $w){
	$result = mysql_query("select Count(*) from $tablename where $w");
	$row = mysql_fetch_array($result);
	return $row[0];
}

function webfunc_list($colname, $tablename, $w, $del=' and checkinfo=true and delaction is NUll'){
	$result = mysql_query("select $colname from $tablename where $w $del");
	$row = mysql_fetch_array($result);
	return $row[$colname];
}


function headinfo(){
	$row = mysql_fetch_array(mysql_query('select * from webconfig'));
	echo '<title>'. webfunc('webname', 'webconfig') .'</title>'."\n";
	echo '<meta name="keywords" content="'.$row['keyword'].'" />'."\n";
	echo '<meta name="description" content="'.$row['description'].'" />'."\n";
}


function copyright(){
	echo webfunc('copyright', 'webconfig');
}



function GetCkVdValue()
{
	@session_start();
	return isset($_SESSION['ckstr']) ? $_SESSION['ckstr'] : '';
}


function ResetVdValue()
{
	@session_start();
	$_SESSION['ckstr'] = '';
	$_SESSION['ckstr_last'] = '';
}

function showtype($id, $i, $table, $tablename, $colname){
	@$row1 = mysql_fetch_array(mysql_query("select $colname from $tablename where id=".$_GET['id']));
	$result = mysql_query("select * from $table where parentid=$id order by orderid asc");
	$i++;
	while($row = mysql_fetch_array($result)){
		if($row['id'] == $row1[0]){
			$selected = ' selected="selected"';
		}
		else{
			$selected = '';
		}
		echo '<option value="'.$row['id'].'"'.$selected.'>';
		for($p=1; $p<$i; $p++){
			echo '　';
		}
		if($row['parentid'] <> 0){
			echo '|- ';
		}
		echo $row["classname"].'</option>';
		showtype($row['id'], $i, $table, $tablename, $colname);
	}
}

function showtype_w($id, $i, $table, $tablename, $colname, $w){
	@$row1 = mysql_fetch_array(mysql_query("select $colname from $tablename where id=".$_GET['id']));
	$result = mysql_query("select * from $table where parentid=$id and $w order by orderid asc");
	$i++;
	while($row = mysql_fetch_array($result)){
		if($row['id'] == $row1[0]){
			$selected = ' selected="selected"';
		}
		else{
			$selected = '';
		}
		echo '<option value="'.$row['id'].'"'.$selected.'>';
		for($p=1; $p<$i; $p++){
			echo '　';
		}
		if($row['parentid'] <> 0){
			echo '|- ';
		}
		echo $row["classname"].'</option>';
		showtype($row['id'], $i, $table, $tablename, $colname, $w);
	}
}

function showtype_w_one($id, $i, $table, $tablename, $colname, $w){
	@$row1 = mysql_fetch_array(mysql_query("select $colname from $tablename where id=".$_GET['id']));
	$result = mysql_query("select * from $table where parentid=$id and $w order by orderid asc");
	$i++;
	while($row = mysql_fetch_array($result)){
		if($row['id'] == $row1[0]){
			$selected = ' selected="selected"';
		}
		else{
			$selected = '';
		}
		echo '<option value="'.$row['id'].'"'.$selected.'>';
		echo $row["classname"].'</option>';
	}
}

function showsmalltype($table, $tablename, $colname){
	@$row1 = mysql_fetch_array(mysql_query("select $colname from $tablename where id=".$_GET['id']));
	$result = mysql_query("select * from $table order by orderid asc");
	while($row = mysql_fetch_array($result)){
		if($row['id'] == $row1[0]){
			$selected = ' selected="selected"';
		}
		else{
			$selected = '';
		}
		echo '<option value="'.$row['id'].'"'.$selected.'>'.$row["classname"].'</option>';
	}
}


function showlisttype($table, $tablename, $colname){
	@$row1 = mysql_fetch_array(mysql_query("select $colname from $tablename where id=".$_GET['id']));
	$result = mysql_query("select * from $table order by orderid desc");
	while($row = mysql_fetch_array($result)){
		if($row['id'] == $row1[0]){
			$selected = ' selected="selected"';
		}
		else{
			$selected = '';
		}
		echo '<option value="'.$row['id'].'"'.$selected.'>'.$row["title"].'</option>';
	}
}

function showinfoclass($id, $i, $infotype, $tablename){
	@$row1 = mysql_fetch_array(mysql_query("select classid from $tablename where id=".$_GET['id']));
	$result = mysql_query("select * from infoclass where parentid=$id and (infotype = '$infotype' or infotype = 'mix') order by orderid asc");
	$i++;
	while($row = mysql_fetch_array($result)){
		if($row['id'] == $row1[0] || $row['id'] == $_GET['tid']){
			$selected = ' selected="selected"';
		}
		else{
			$selected = '';
		}
		echo '<option value="'.$row['id'].'"'.$selected.'>';
		for($p=1; $p<$i; $p++){
			echo '　';
		}
		if($row['parentid'] <> 0){
			echo '|- ';
		}	
		echo $row["classname"].'</option>';
		showinfoclass($row['id'], $i, $infotype, $tablename);
	}
}

function taginfoattr($id, $i, $infotype, $tablename){
	@$row1 = mysql_fetch_array(mysql_query("select classid from $tablename where id=".$_GET['id']));
	$result = mysql_query("select * from infoclass where parentid=$id and (infotype <> '$infotype' or infotype = 'mix') order by orderid asc");
	$i++;
	while($row = mysql_fetch_array($result)){
		if($row['id'] == $row1[0]){
			$selected = ' selected="selected"';
		}
		else{
			$selected = '';
		}
		echo '<option value="'.$row['id'].'"'.$selected.'>';
		for($p=1; $p<$i; $p++){
			echo '　';
		}
		if($row['parentid'] <> 0){
			echo '|- ';
		}	
		echo $row["classname"].'</option>';
		taginfoattr($row['id'], $i, $infotype, $tablename);
	}
}


function showorderid($tablename){
	$row = mysql_fetch_array(mysql_query("select max(orderid) from $tablename"));
	if($row[0] == ''){
		$orderid = 0;
	}
	else{
		$orderid = $row[0] + 1;
	}
	echo $orderid;
}
function getorderid($tablename){
	$row = mysql_fetch_array(mysql_query("select max(orderid) from $tablename"));
	if($row[0] == ''){
		$orderid = 0;
	}
	else{
		$orderid = $row[0] + 1;
	}
	return $orderid;
}


function page($page, $totalpage, $pagenum, $total,$parameter){
	$previous = $page - 1;
	if($totalpage == $page){
		$next = $page;
	}
	else{
		$next = $page + 1;  
	}
	if($total < $pagenum){
		return '<div class="pageinfo">total<span>'.$totalpage.'</span>page<span>'.$total.'</span>records</div>';
	}
	else{
		if($totalpage < 10){
			$pagecontent = '<div class="page_list">';
			if($page > 1){ 
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?'.$parameter.'">&lt;&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;&lt;</a>';
			}
			if($page > 1){ 
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$previous.'&'.$parameter.'">&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;</a>';
			}
			for($i=1; $i <= $totalpage; $i++){
				if($page == $i){
					$pagecontent .= '<a href="javascript:;" class="on">'.$i.'</a>';
				}
				else{
					$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$i.'&'.$parameter.'" class="num">'.$i.'</a>';
				}
			}
			if($page < $totalpage){
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$next.'&'.$parameter.'">&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;</a>';
			}
			if($page < $totalpage){
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$totalpage.'&'.$parameter.'">&gt;&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;&gt;</a>';
			}
			$pagecontent .= '</div>';
			return $pagecontent;
		}
		else{
			
			$pagecontent = '<div class="page_list">';
			if($page > 1){
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?'.$parameter.'">&lt;&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;&lt;</a>';
			}
			if($page > 1){
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$previous.'&'.$parameter.'">&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;</a>';
			}
			
			if($page == 1 or $page == 2 or $page == 3){
				$m = 1;
				$b = 7;
			}
			
			if ($page > 3 and $page < $totalpage-2){
				$m = $page-3;
				$b = $page+3;
			}
			
			if($page == $totalpage or $page == $totalpage-1 or $page == $totalpage-2){
				$m = $totalpage-7;
				$b = $totalpage;
			}
			if($page > 4){
				$pagecontent .= '<a href="javascript:;">...</a>';
			}
			for($i=$m; $i <= $b; $i++){
				if($page == $i){
					$pagecontent .= '<a href="javascript:;" class="on">'.$i.'</a>';
				}
				else{
					$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$i.'&'.$parameter.'" class="num">'.$i.'</a>';
				}
			}
			if ($page < $totalpage-3){
				$pagecontent .= '<a href="javascript:;">...</a>';
			}
			if($page < $totalpage){ 
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$next.'&'.$parameter.'">&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;</a>';
			}
			if($page < $totalpage){ 
				$pagecontent .= '<a href="'.$_SERVER['PHP_SELF'].'?page='.$totalpage.'&'.$parameter.'">&gt;&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;&gt;</a>';
			}
			$pagecontent .= '</div>';
			return $pagecontent;
		}
	}
}


function page_html($page, $totalpage, $pagenum, $total,$parameter){
	$previous = $page - 1;
	if($totalpage == $page){
		$next = $page;
	}
	else{
		$next = $page + 1;   
	}
	if($total < $pagenum){
		return '<div class="pageinfo">sum<span>'.$totalpage.'</span>pages<span>'.$total.'</span>record</div>';
	}
	else{
		if($totalpage < 10){
			$pagecontent = '<div class="page_list">';
			if($page > 1){ 
				$pagecontent .= '<a href="'.$parameter.'">&lt;&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;&lt;</a>';
			}
			if($page > 1){ 
				$pagecontent .= '<a href="'.$parameter.'?page='.$previous.'">&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;</a>';
			}
			for($i=1; $i <= $totalpage; $i++){
				if($page == $i){
					$pagecontent .= '<a href="javascript:;" class="on">'.$i.'</a>';
				}
				else{
					$pagecontent .= '<a href="'.$parameter.'?page='.$i.'" class="num">'.$i.'</a>';
				}
			}
			if($page < $totalpage){
				$pagecontent .= '<a href="'.$parameter.'?page='.$next.'">&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;</a>';
			}
			if($page < $totalpage){
				$pagecontent .= '<a href="'.$parameter.'?page='.$totalpage.'">&gt;&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;&gt;</a>';
			}
			$pagecontent .= '</div>';
			return $pagecontent;
		}
		else{
			
			$pagecontent = '<div class="page_list">';
			if($page > 1){
				$pagecontent .= '<a href="'.$parameter.'">&lt;&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;&lt;</a>';
			}
			if($page > 1){
				$pagecontent .= '<a href="'.$parameter.'?page='.$previous.'">&lt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&lt;</a>';
			}
			
			if($page == 1 or $page == 2 or $page == 3){
				$m = 1;
				$b = 7;
			}
			
			if ($page > 3 and $page < $totalpage-2){
				$m = $page-3;
				$b = $page+3;
			}
			
			if($page == $totalpage or $page == $totalpage-1 or $page == $totalpage-2){
				$m = $totalpage-7;
				$b = $totalpage;
			}
			if($page > 4){
				$pagecontent .= '<a href="javascript:;">...</a>';
			}
			for($i=$m; $i <= $b; $i++){
				if($page == $i){
					$pagecontent .= '<a href="javascript:;" class="on">'.$i.'</a>';
				}
				else{
					$pagecontent .= '<a href="'.$parameter.'?page='.$i.'" class="num">'.$i.'</a>';
				}
			}
			if ($page < $totalpage-3){
				$pagecontent .= '<a href="javascript:;">...</a>';
			}
			if($page < $totalpage){
				$pagecontent .= '<a href="'.$parameter.'?page='.$next.'">&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;</a>';
			}
			if($page < $totalpage){
				$pagecontent .= '<a href="'.$parameter.'?page='.$totalpage.'">&gt;&gt;</a>';
			}
			else{
				$pagecontent .= '<a href="javascript:;">&gt;&gt;</a>';
			}
			$pagecontent .= '</div>';
			return $pagecontent;
		}
	}
}

function ajaxpage($page, $totalpage, $pagenum, $total, $tid, $attr, $keyword,$urlstring,$url=''){
	$previous = $page - 1;
	if($totalpage == $page){
		$next = $page;
	}
	else{
		$next = $page + 1;   
	}
	if($total < $pagenum){
		echo '<div class="pageinfo">sum<span>'.$totalpage.'</span>pages<span>'.$total.'</span>record</div>';
	}
	else{
		
		if ($totalpage < 10){
			
			echo '<div class="page_list">';
			if($page > 1){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\'1\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&lt;&lt;</a>';
			}
			else{
				echo '<a href="javascript:;">&lt;&lt;</a>';
			}
			if($page > 1){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$previous.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&lt;</a>';
			}
			else{
				echo '<a href="javascript:;">&lt;</a>';
			}
			for($i=1; $i <= $totalpage; $i++){
				if($page == $i){
					echo '<a href="javascript:;" class="on">'.$i.'</a>';
				}
				else{
					echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$i.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')" class="num">'.$i.'</a>';
				}
			}
			if($page < $totalpage){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$next.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&gt;</a>';
			}
			else{
				echo '<a href="javascript:;">&gt;</a>';
			}
			if($page < $totalpage){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$totalpage.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&gt;&gt;</a>';
			}
			else{
				echo '<a href="javascript:;">&gt;&gt;</a>';
			}
		}
		else{
			
			echo '<div class="page_list">';
			if($page > 1){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\'1\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&lt;&lt;</a>';
			}
			else{
				echo '<a href="javascript:;">&lt;&lt;</a>';
			}
			if($page > 1){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$previous.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&lt;</a>';
			}
			else{
				echo '<a href="javascript:;">&lt;</a>';
			}
			
			if($page == 1 or $page == 2 or $page == 3){
				$m = 1;
				$b = 7;
			}
			
			if ($page > 3 and $page < $totalpage-2){
				$m = $page-3;
				$b = $page+3;
			}
			
			if($page == $totalpage or $page == $totalpage-1 or $page == $totalpage-2){
				$m = $totalpage-7;
				$b = $totalpage;
			}
			if($page > 4){
				echo '<a href="javascript:;">...</a>';
			}
			for($i=$m; $i <= $b; $i++){
				if($page == $i){
					echo '<a href="javascript:;" class="on">'.$i.'</a>';
				}
				else{
					echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$i.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')" class="num">'.$i.'</a>';
				}
			}
			if ($page < $totalpage-3){
				echo '<a href="javascript:;">...</a>';
			}
			if($page < $totalpage){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$next.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&gt;</a>';
			}
			else{
				echo '<a href="javascript:;">&gt;</a>';
			}
			if($page < $totalpage){
				echo '<a href="javascript:;" onclick="pagelist'.$url.'(\''.$totalpage.'\',\''.$tid.'\',\''.$attr.'\',\''.$keyword.'\',\''.$urlstring.'\')">&gt;&gt;</a>';
			}
			else{
				echo '<a href="javascript:;">&gt;&gt;</a>';
			}		
		}
		echo '</div>';  
	}
}



function getrealsize($size){
	$kb = 1024;          // Kilobyte
	$mb = 1024 * $kb;    // Megabyte
	$gb = 1024 * $mb;    // Gigabyte
	$tb = 1024 * $gb;    // Terabyte
	if($size < $kb){
		return $size." B";
	}
	else if($size < $mb){
		return round($size/$kb,2)." KB";
	}
	else if($size < $gb){
		return round($size/$mb,2)." MB";
	}
	else if($size < $tb){
		return round($size/$gb,2)." GB";
	}
	else{
		return round($size/$tb,2)." TB";
	}
}


function restrlen($sourcestr, $cutlength = 10, $etc = '...'){
	$returnstr = '';
	$i = 0;
	$n = 0.0;
	$str_length = strlen($sourcestr); 
	while( ($n < $cutlength) and ($i < $str_length) ){
	   $temp_str = substr($sourcestr, $i, 1);
	   $ascnum = ord($temp_str); 
	   if ( $ascnum >= 252) 
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 6);
			$i = $i + 6; 
			$n++; 
	   }
	   elseif ( $ascnum >= 248 )
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 5);
			$i = $i + 5; 
			$n++; 
	   }
	   elseif ( $ascnum >= 240 ) 
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 4);
			$i = $i + 4; 
			$n++; 
	   }
	   elseif ( $ascnum >= 224 ) 
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 3);
			$i = $i + 3 ; 
			$n++; 
	   }
	   elseif ( $ascnum >= 192 ) 
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 2); 
			$i = $i + 2; 
			$n++; 
	   }
	   elseif ( $ascnum>=65 and $ascnum<=90 and $ascnum!=73) 
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 1);
			$i = $i + 1; 
			$n++; 
	   }
	   elseif ( !(array_search($ascnum, array(37, 38, 64, 109 ,119)) === FALSE) ) 
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 1);
			$i = $i + 1; 
			$n++; 
	   }
	   else 
	   {
			$returnstr = $returnstr . substr($sourcestr, $i, 1);
			$i = $i + 1; 
			$n = $n + 0.5; 
	   }
	}
	if ( $i < $str_length )
	{
	   $returnstr = $returnstr.$etc; 
	}
	return $returnstr;
}


function showpage()
{
    global $page,$pages,$prepage,$nextpage,$queryString; //param from genpage function
    $shownum =10/2;
    $startpage = ($page>=$shownum)?$page-$shownum:0;
    $endpage = ($page+$shownum<=$pages)?$page+$shownum:$pages;
   
    echo "sum".($pages+1)."page:&nbsp;"; 
    if($page>0)echo "<a href=$PHP_SELF?page=0$queryString>Home page</a>";
    if($startpage>0)
        echo " ... <b><a href=$PHP_SELF?page=".($page-$shownum*2)."$queryString>&laquo;</a></b>";
    for($i=$startpage;$i<=$endpage;$i++)
    {
        if($i==$page)    echo "&nbsp;<b>[".($i+1)."]</b>&nbsp;";
        else        echo "&nbsp;<a href=$PHP_SELF?page=$i$queryString>".($i+1)."</a>&nbsp;";
    }
    if($endpage<$pages)
        echo "<b><a href=$PHP_SELF?page=".($page+$shownum*2)."$queryString>&raquo;</a></b> ... ";
    if($page<$pages)
        echo "<a href=$PHP_SELF?page=$pages$queryString>The last page</a>";

}

 
function showpage1()
{
	$fenlei=$_GET["pp_id"];
    global $page,$pages,$prepage,$nextpage,$queryString; //param from genpage function
    $shownum =10/2;
    $startpage = ($page>=$shownum)?$page-$shownum:0;
    $endpage = ($page+$shownum<=$pages)?$page+$shownum:$pages;
   
    echo "sum".($pages+1)."page:&nbsp;"; 
    if($page>0)echo "<a href=$PHP_SELF?pp_id=$fenlei&page=0$queryString>Home page</a>";
    if($startpage>0)
        echo " ... <b><a href=$PHP_SELF?pp_id=$fenlei&page=".($page-$shownum*2)."$queryString>&laquo;</a></b>";
    for($i=$startpage;$i<=$endpage;$i++)
    {
        if($i==$page)    echo "&nbsp;<b>[".($i+1)."]</b>&nbsp;";
        else        echo "&nbsp;<a href=$PHP_SELF?pp_id=$fenlei&page=$i$queryString>".($i+1)."</a>&nbsp;";
    }
    if($endpage<$pages)
        echo "<b><a href=$PHP_SELF?pp_id=$fenlei&page=".($page+$shownum*2)."$queryString>&raquo;</a></b> ... ";
    if($page<$pages)
        echo "<a href=$PHP_SELF?pp_id=$fenlei&page=$pages$queryString>The last page</a>";

}

function utf8substr($str, $from, $len)
{
   return preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
                      '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*/s',
                      '$1',$str);
}


function shownext($orderid,$tablename,$w,$pageurl,$type,$parameter=''){
    $query="select * from $tablename where orderid<$orderid and $w limit 1";
    $result=mysql_fetch_array(mysql_query($query));
	if($type=='ajax'){
		if($result==''){
			echo "<a href='javascript:;' title='Is the last topic'>Is the last topic</a>";
		}else{
			$nextid=$result["id"];
			$title=$result["title"];
			echo "<a href=\"javascript:show_window('caipu','id=".$nextid."',1)\" title='Next topic'>".$title."</a>";
		}
	}else{
		if($result==''){
			echo "<a href='#' title='Is the last topic'>Is the last topic</a>";
		}else{
			$nextid=$result["id"];
			$title=$result["title"];
			echo "<a href='".$pageurl."?id=".$nextid."&".$parameter."' title='Next topic'>".$title."</a>";
		}
	}
}
function showpre($orderid,$tablename,$w,$pageurl,$type,$parameter=''){
    $query="select * from $tablename where orderid>$orderid and $w limit 1";
    $result=mysql_fetch_array(mysql_query($query));
	if($type=='ajax'){
		if($result==''){
			echo "<a href='javascript:;' title='Is the first topic'>Is the first topic</a>";
		}else{
			$nextid=$result["id"];
			$title=$result["title"];
			echo "<a href=\"javascript:show_window('caipu','id=".$nextid."',1)\" title='Next topic'>".$title."</a>";
		}
	}else{
		if($result==''){
			echo "<a href='#' title='Is the first topic'>Is the first topic</a>";
		}else{
			$nextid=$result["id"];
			$title=$result["title"];
			echo "<a href='".$pageurl."?id=".$nextid."&".$parameter."' title='previous'>".$title."</a>";
		}
	}
}


function Text2Html($txt){
$txt = str_replace(" ","　",$txt);
$txt = str_replace("<","&lt;",$txt);
$txt = str_replace(">","&gt;",$txt);
$txt = preg_replace("/[rn]{1,}/isU","
rn",$txt);
return $txt;
} 


function SpHtml2Text($str)
{
 $str = preg_replace("/<sty(.*)\\/style>|<scr(.*)\\/script>|<!--(.*)-->/isU","",$str);
 $alltext = "";
 $start = 1;
 for($i=0;$i<strlen($str);$i++)
 {
  if($start==0 && $str[$i]==">")
  {
   $start = 1;
  }
  else if($start==1)
  {
   if($str[$i]=="<")
   {
    $start = 0;
    $alltext .= " ";
   }
   else if(ord($str[$i])>31)
   {
    $alltext .= $str[$i];
   }
  }
 }
 $alltext = str_replace("　"," ",$alltext);
 $alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);
 $alltext = preg_replace("/[ ]+/s"," ",$alltext);
 return $alltext;
}



function alert($msg) { 
echo "<script>alert('$msg!');</script>";
}



function goback(){
echo "<script>window.history.back();</script>\n<script>Location.refresh();</script>";
}

function gourl($url){
echo "<script>window.location.href='".$url."';</script>";
}


function pregstr($find_str,$str){
preg_match('/('.$find_str.')/',$str,$preg_resault);
	if ($preg_resault[0]!=''){
		return true;
	}else{
		return false;
	}
}

function array_insert($myarray,$value,$position=0)
{
   $fore=($position==0)?array():array_splice($myarray,0,$position);
   $fore[]=$value;
   $ret=array_merge($fore,$myarray);
   return $ret;
}

function change_act_bigtype($bigtype){
	 if(pregstr($bigtype,"news,fdpx,whyc")){
		  return 'two';
		  exit();
	 }else{
		  return 'three';
		  exit();
	 }
}



function marquee($text,$action,$s1,$s2){
   echo '<marquee direction="'.$action.'" scrollamount="'.$s1.'" scrolldelay="'.$s2.'" onmouseover="this.stop()" onmouseout="this.start()">'.$text.'</marquee>';	
}


function ad_show($id,$wdith,$height='auto',$count=1,$css1='',$css2=''){
    $result = mysql_query("select * from admanager where classid=".$id." and checkinfo=true order by orderid desc, id desc limit ".$count."");
	$recount=mysql_num_rows($result);
	if($recount!=0){
	   while($row = mysql_fetch_array($result)){
		  echo $css1.'<a href="'.$row['linkurl'].'" target="_blank" title="'.$title.'"><img src="'.$row['picurl'].'" width="'.$wdith.'" height="'.$height.'" title="'.$title.'" /></a>'.$css2;
	   }
	}
}


function get_time_cha($time_one,$time_two,$type=0){ 

   $time_diff=abs($time_one-$time_two); 
   $diff_time = array();   
   $diff_time["year"] = 0; 
   if($time_diff > 31536000) 
  $diff_time["year"] = floor($time_diff / 31536000); 
   $time_diff = $time_diff - $diff_time["year"] * 31536000; 
   $diff_time["month"] = 0; 
   if($time_diff > 2592000) 
  $diff_time["month"] = floor($time_diff / 2592000); 
    
   $time_diff = $time_diff - $diff_time["month"] * 2592000;   
    
   $diff_time["day"] = 0; 
   if($time_diff > 86400) 
  $diff_time["day"] = floor($time_diff / 86400); 
    
   $time_diff = $time_diff - $diff_time["day"] * 86400;   
    
   $diff_time["hour"] = 0; 
   if($time_diff > 3600) 
  $diff_time["hour"] = floor($time_diff / 3600); 
    
   $time_diff = $time_diff - $diff_time["hour"] * 3600;       
    
   $diff_time["minute"] = 0; 
   if($time_diff > 60)  
  $diff_time["minute"] = floor($time_diff / 60);
  
  $diff_time["seconds"] = 0; 
   if($time_diff <= 60)  
  $diff_time["seconds"] = floor($time_diff);
  
  
  
   $times='';
   $time_diff = $time_diff - $diff_time["minute"] * 60;    
   
   if($type==0){
	   if(intval($diff_time["year"]) > 0){ 
	   $times.=$diff_time["year"]."year"; 
	   } 
	   if(intval($diff_time["month"]) > 0){ 
	   $times.=$diff_time["month"]."month"; 
	   } 
	   if(intval($diff_time["day"]) > 0){ 
	   $times.=$diff_time["day"]."day"; 
	   } 
	   if(intval($diff_time["hour"]) > 0){ 
	   $times.=$diff_time["hour"]."hour"; 
	   } 
	   if(intval($diff_time["minute"]) > 0){ 
	   $times.=$diff_time["minute"]."minute"; 
	   }
	   if(intval($diff_time["seconds"]) >0){ 
	   $times.=$diff_time["seconds"]."seconds"; 
	   } 
	  return $times;
   }else{
	   if(intval($diff_time["year"]) > 0){ 
	   $times=$diff_time["year"]."year ago";
	   return $times;
	   exit();
	   } 
	   if(intval($diff_time["month"]) > 0){ 
	   $times=$diff_time["month"]."month ago";
	   return $times;
	   exit();
	   } 
	   if(intval($diff_time["day"]) > 0){ 
	   $times=$diff_time["day"]."day ago"; 
	   return $times;
	   exit();
	   } 
	   if(intval($diff_time["hour"]) > 0){ 
	   $times=$diff_time["hour"]."hour ago"; 
	   return $times;
	   exit();
	   } 
	   if(intval($diff_time["minute"]) > 0){ 
	   $times=$diff_time["minute"]."minute ago"; 
	   return $times;
	   exit();
	   }
	   if(intval($diff_time["seconds"]) >0){ 
	   $times=$diff_time["seconds"]."seconds ago"; 
	   return $times;
	   exit();
	   } 
   }
   
 } 
function timedb($time1,$time2){
	if(strtotime($time1)>strtotime($time2)){
		return true;
	}else{
		return false;
	}
}


function save_file($filename,$path,$content){
	
	$fp=fopen($path.$filename,"w");
	fwrite($fp,$content);
	fclose($fp);
}

function ls($dir, $mask /*.php$|.txt$*/)
{
       static $i = 0;
       $files = Array();
       $d = opendir($dir);
       while ($file = readdir($d))
       {
               if ($file == '.' || $file == '..' || eregi($mask, $file) ) continue;
               if (is_dir($dir.'/'.$file))
               {
                       $files += ls($dir.'/'.$file, $mask);
                       continue;
               }
               $files[$i++] =iconv('gbk','utf-8',$file);
			   //$extend = pathinfo($file);
               //echo strtolower($extend["extension"]),'<br/>';
       }
       return $files;
}

function get_member_info($user_id,$colname){
	$row = mysql_fetch_array(mysql_query("select $colname from member where id=".$user_id." "));
	return $row[$colname];
}

function needlogin($user,$url=''){
    if($_COOKIE[$user] == Null){
	   if($url==''){
	      alert('Please first landing');
		  goback();
	   }else{
		  gourl($url);   
	   }
    }	
}


function del_dir($dir,$time){	
	if(!($mydir=@dir($dir))){
		return;
	}
	while($file=$mydir->read()){
		if(is_dir("$dir$file") && $file!='.' && $file!='..'){ 
			@chmod("$dir$file", 0777);
			del_dir("$dir$file"); 
		}elseif(is_file("$dir/$file")){
			$file_time=@stat($file);	
			if(time()-$file_time>$time){
				@chmod("$dir/$file", 0777);
				@unlink("$dir/$file");
			}
		}
	}
	$mydir->close();
	@chmod($dir, 0777);
	@rmdir($dir);
}
?>

